//
//  HomeTableViewCell.swift
//  SwiftDemo
//
//  Created by admin on 2020/10/15.
//

import UIKit

class HomeTableViewCell: UITableViewCell {
    lazy var backView: UIView = UIView()
    var subImage: UIImageView?
    var nameLabe: UILabel?
    var contentLabe: UILabel?

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        backgroundColor = .clear
        selectionStyle = .none
        setupView()
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
}

extension HomeTableViewCell {
    func setupView() {
        backView.frame = CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: contentView.frame.size.height)
        contentView.addSubview(backView)

        // 间隔
        let sc_w = 10
        let image_w = 50

        subImage = UIImageView()
        subImage?.image = UIImage(named: "qp-gr-sel")

        subImage?.frame = CGRect(x: sc_w, y: sc_w, width: image_w, height: image_w)
        contentView.addSubview(subImage!)

        nameLabe = UILabel()
        nameLabe?.text = "占位"
        nameLabe?.font = UIFont.systemFont(ofSize: 15)
        nameLabe?.textColor = UIColor.red
        nameLabe?.frame = CGRect(x: sc_w * 2 + image_w, y: sc_w, width: Int(SCREEN_WIDTH) - sc_w * 3 - image_w, height: Int(30))
        contentView.addSubview(nameLabe!)

        contentLabe = UILabel()
        contentLabe?.text = "详情    // 懒加载的本质是,在第一次使用的时候执行闭包,将闭包的返回值赋值给属性"
        contentLabe?.numberOfLines = 0
        contentLabe?.font = UIFont.systemFont(ofSize: 12)
        contentLabe?.frame = CGRect(x: sc_w * 2 + image_w, y: sc_w + 30, width: Int(SCREEN_WIDTH) - sc_w * 3 - image_w, height: Int(30))
        contentView.addSubview(contentLabe!)
    }
}
